package com.oscarmovie.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.oscarmovie.model.Account;

public class AccountDaoImpl extends HibernateDaoSupport implements AccountDao {

	public Account load(int id) {
		Account account = (Account)getSession().load(Account.class, id);
		return account;
	}
	
	public List<Account> loadAll() {
		Query query = getSession().createQuery("from Account");
		query.setCacheable(true);
		List<Account> list = (List<Account>)query.list();
		return list;
	}

	public void save(Account account) {
		getSession().saveOrUpdate(account);
	}

	public Account loadByWeiboId(String weiboId) {
		Query query = getSession().createQuery("from Account account where account.weiboId = :weiboId");
		query.setString("weiboId", weiboId);
		Account account = (Account)query.uniqueResult();
		return account;
	}
	
}
